cc.Class({
    extends: cc.Component,

    properties: {
        lb_username: cc.Label,
        lb_email: cc.Label,
        lb_desc: cc.Label,

        ed_key: cc.EditBox,

        lb_pwd:cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.itemData = null;
        this.lb_pwd.string = '';
    },

    start() {

    },


    initWithItemData(itemData){
        this.itemData = itemData;
        this.lb_username.string = itemData.uname;
        this.lb_email.string = itemData.email;
        this.lb_desc.string = itemData.desc;
    },


    btn_backClicked() {
        this.node.destroy();
    },

    btn_queryClicked(){
        let key = this.ed_key.string.trim();
        if(key.length < 1){
            G.showToast('请输入key...');
            return;
        }

        let md5Key = G.md5(key);
        if(md5Key === G.allData.key){
            G.netApi.item_query({key:key,md5Key:md5Key,pwd:this.itemData.pwd},(err,data)=>{
               if(err){
                   G.showToast('查询失败! err:' + err);
               } else{
                   this.lb_pwd.string = data.pwd;
               }
            });
        }else{
            G.showToast('key匹配错误!');
            this.ed_key.string = '';
            this.lb_pwd.string = '';
        }
    },

    btn_deleteClicked(){
        G.winMgr.showDeleteDialog(this.itemData);
    },
});
